﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace McsWeb.Models
{
    public class BaseController : Controller
    {

        /// <summary>
        /// 获取或设置 依赖注入服务提供者
        /// </summary>
        public IServiceProvider ServiceProvider { get; set; }


        /// <summary>
        /// 返回JsonResult      
        /// </summary>
        /// <param name="data">数据</param>
        /// <param name="behavior">行为</param>
        /// <param name="dateFormatStr">json中dateTime类型的格式</param>
        /// <returns>Json</returns>
        protected JsonResult JsonEx(object data, JsonRequestBehavior behavior, string dateFormatStr = "yyyy-MM-dd")
        {
            return new JsonResultEx
            {
                Data = data,
                JsonRequestBehavior = behavior,
                DateFormatString = dateFormatStr
            };
        }

        /// <summary>
        /// 返回JsonResult     
        /// </summary>
        /// <param name="data">数据</param>
        /// <param name="dateFormatStr">数据格式</param>
        /// <returns>Json</returns>
        protected JsonResult JsonEx(object data, string dateFormatStr)
        {
            return new JsonResultEx
            {
                Data = data,
                DateFormatString = dateFormatStr
            };
        }
        /// <summary>
        /// 返回JsonResult     
        /// </summary>
        /// <param name="data">数据</param>
        /// <returns>Json</returns>
        protected JsonResult JsonEx(object data)
        {
            return new JsonResultEx
            {
                Data = data
            };
        }
    }
}